import React, { useEffect, memo } from 'react';
import "./index.less"
import { Toast, Dialog, TextArea } from 'antd-mobile'

// disabledUrlStatus 禁止跳转的状态
function ListItem({ item, history, detailUrl, disabledUrlStatus, listFields, cancelRow, time }) {

    const getStatusTxt = (status, statusList) => {
        return statusList.find(el => el.value == status)?.label
    }

    const getcolor = (status) => {
        if (status == 'WAIT_FINISH' || status == 'CANCEL_TO_BE_CONFIRMED') {
            return "WAIT_FINISH"
        } else if (status == 'PROCESSING' || status == 'REPAIRING') {
            return "PROCESSING"
        } else if (status == 'REPAIRED_TO_BE_CONFIRMED') {
            return 'REPAIRED_TO_BE_CONFIRMED'
        }
    }

    const cancelItem = (e) => {
        e.stopPropagation();
        cancelRow(item)
    }

    const linkDetail = () => {
        if (!detailUrl) return
        if (time && item['strategyNames'].indexOf("夜班") > 0) {
            var now = new Date();
            var hours = now.getHours();
            if (hours < 16) {
                Toast.show({
                    content: '夜班点检任务，要16:00后才能执行:',
                })
                return
            }
        }

        if (disabledUrlStatus && disabledUrlStatus.split(',').includes(item['status'])) return
        history.push(detailUrl, { no: item.no, name: item.name })
    }
    return (
        <div className="box" onClick={linkDetail}>
            <div className="boxTit">
                <span className="boxTitSize">{listFields.title.label}:{item[listFields.title.value]}</span>
                <span  className="boxTitSize">{item.inventoryStatus == 'WAIT_CONFIRM' ? '待盘点' : (item.inventoryStatus == 'COMPLETED' ? '已盘点' : '待确认')}</span>

                {/* {
                    listFields.title.methods?.length ?
                        <div className="t-right">
                            {
                                listFields.title.methods.map((em, index) => {
                                    return (
                                        <React.Fragment key={index}>
                                            {
                                                item['status'] == em['status'] ? <span onClick={cancelItem}>{em.label}</span> : null
                                            }
                                        </React.Fragment>
                                    )
                                })
                            }
                        </div> : null
                } */}
            </div>
            <div className="boxContent">
                {
                    listFields.children.length ? listFields.children.map((el, index) =>
                        <div className="bcLine borderB" key={index}>
                            <span className="bcLineSize">{el.label}:</span>
                            {
                                el.isStatus ?
                                    <span className={`bcLineSize ${getcolor(item[el.value])}`}>{getStatusTxt(item[el.value], el.statusList)}</span> :
                                    <span className="bcLineSize">{item[el.value]}</span>
                            }

                        </div>
                    ) : null
                }
            </div>
        </div>
    );
}

export default memo(ListItem);
